package com.alongstudio.account.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.alongstudio.account.commons.exception.BusinessException;
import com.alongstudio.account.commons.utils.BeanUtil;
import com.alongstudio.account.constants.SystemConstant;
import com.alongstudio.account.dao.ICategoryDao;
import com.alongstudio.account.dao.base.impl.BaseDao;
import com.alongstudio.account.entity.Category;
import com.alongstudio.account.vo.CategoryVo;
@Repository(value="CategoryDao")
public class CategoryDao extends BaseDao<Category> implements ICategoryDao {

//	@Override
//	public List<Category> getAllCategory(String userId, String type) throws BusinessException {
//		String hql = "from Category c where c.type ='"+type+"' and c.clientUser.id='"+userId+"'";
//		return queryByHql(hql);
//	}

	@Override
	public List<Category> getFirstClassCategory(String userId, String type)
			throws BusinessException {
		String hql ="from Category c where c.delTag='"+SystemConstant.DEL_TAG_NOT_DELETE+"' and c.type='" + type + "' and c.clientUser.id="+userId+" and c.grade="
		+ SystemConstant.TREE_GRADE_FIRST + " order by c.sortNum";
		return queryByHql(hql);
	}
	
	@Override
	public List<String> getFirstClassCategoryIds(String userId, Integer type)
			throws BusinessException {
		// TODO Auto-generated method stub
		return null;
	}



	@Override
	public List<Category> getSubClassCategoryByParentId(String parentId)
			throws BusinessException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Integer queryMaxSortNum(CategoryVo vo) throws BusinessException {
		String hql = "select max(c.sortNum) from Category c where c.type='" + vo.getType() + "'";
		String parentId = vo.getParentId();
		boolean hasParent = parentId != null && !parentId.isEmpty();
		// 如果有父节点
		if (hasParent) {
			hql += " and c.parent.id=" + parentId;
		}
		Integer maxSortNum = this.countByHql(hql);
		return maxSortNum;
	}
	
	
}

